/**
 * 环境配置
 */
require('dotenv').config();

const baseConfig = {
  port: process.env.PORT || 3001,
  jwtSecret: process.env.JWT_SECRET || 'your-jwt-secret',
  jwtExpires: process.env.JWT_EXPIRES || '7d',
  uploadDir: process.env.UPLOAD_DIR || 'public/uploads',
  cors: {
    origin: process.env.CORS_ORIGIN || '*',
    methods: process.env.CORS_METHODS ? process.env.CORS_METHODS.split(',') : ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
    allowedHeaders: process.env.CORS_ALLOWED_HEADERS ? process.env.CORS_ALLOWED_HEADERS.split(',') : ['Content-Type', 'Authorization']
  },
  database: {
    host: process.env.DB_HOST || '120.27.196.69',
    port: parseInt(process.env.DB_PORT) || 3306,
    username: process.env.DB_USER || 'mall',
    password: process.env.DB_PASSWORD || 'mall',
    dialect: 'mysql',
    pool: {
      max: 2,
      min: 0,
      acquire: 30000,
      idle: 10000
    },
    timezone: '+08:00',
    define: {
      timestamps: true,
      paranoid: false,
      createdAt: 'create_time',
      updatedAt: 'update_time',
      underscored: true
    }
  }
};

module.exports = {
  development: {
    ...baseConfig,
    logLevel: process.env.LOG_LEVEL || 'debug',
    database: {
      ...baseConfig.database,
      database: process.env.DB_NAME || 'shop'
    }
  },
  
  test: {
    ...baseConfig,
    logLevel: 'debug',
    database: {
      ...baseConfig.database,
      database: process.env.TEST_DB_NAME || 'shop_test'
    }
  },
  
  production: {
    ...baseConfig,
    logLevel: process.env.LOG_LEVEL || 'info',
    database: {
      ...baseConfig.database,
      database: process.env.DB_NAME || 'shop',
      pool: {
        max: 5,
        min: 0,
        acquire: 30000,
        idle: 10000
      }
    }
  },
  
  // 微信支付配置
  wxpay: {
    mchId: process.env.WXPAY_MCH_ID || '1900000109',  // 商户号
    apiKey: process.env.WXPAY_API_KEY || 'BaDrCKEg8YJpTc7KbTRGZkTPZcuRcQfp',  // API密钥
    notifyUrl: process.env.WXPAY_NOTIFY_URL || 'https://example.com/api/miniapp/payment/notify'  // 支付结果通知URL
  }
}; 